package com.mairuide.transactionstreamcount.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mairuide._frame.base.BaseController;
import com.mairuide.bill.DealFlow;
import com.mairuide.bill.DealFlowService;
import com.mairuide.bill.dto.DealFlowDto;
import com.mairuide.bill.information.PersonCards;
import com.mairuide.bill.information.PersonInformation;
import com.mairuide.bill.information.PersonInformationParams;
import com.mairuide.bill.information.PersonInformationService;
import com.mairuide.bill.information.tag.PersonTag;
import com.mairuide.bill.information.tag.PersonTagService;
import com.mairuide.bill.utils.DateUtils;
import com.mairuide.entity.PageResult;
import com.mairuide.entity.Result;
import com.mairuide.entity.StatusCode;
import com.mairuide.phone.PhoneRecord;
import com.mairuide.phone.import_phone.PhoneRecordingService;
import com.mairuide.transactionstreamcount.service.TransactionStreamD3Service;

/**
 * Created by 敲代码的卡卡罗特
 * on 2018/12/13 14:10.
 */
@Controller
@CrossOrigin
@RequestMapping("/bill/stream/d3")
public class TransactionStreamD3Controller extends BaseController {
    @Autowired
    private TransactionStreamD3Service transactionStreamD3Service;
    
    @Autowired
    private DealFlowService dealFlowService;
    
    @Autowired
    private PersonInformationService personInformationService;
    
    @Autowired
    private PersonTagService personTagService;
    
    @Autowired
    private PhoneRecordingService phoneRecordingService;

    @RequestMapping(value = "/leftTreeEditDialogInit", method = RequestMethod.GET)
    public Object leftTreeEditDialogInit(ModelMap model) {
        return "/account/leftTreeEditDialog";
    }
    @RequestMapping(value = "/leftTreeDialogAccountBodyInit", method = RequestMethod.GET)
    public Object leftTreeDialogAccountBodyInit(ModelMap model) {
        return "/account/leftTreeBodyDialog";
    }
    @RequestMapping(value = "/leftTreeDialogAccountBodyCardInit", method = RequestMethod.GET)
    public Object leftTreeDialogAccountBodyCardInit(ModelMap model) {
    	return "/account/leftTreeCardDialog";
    }
    @RequestMapping(value = "/moreDetailDialogInit", method = RequestMethod.GET)
    public Object moreDetailDialogInit(ModelMap model) {
        return "/account/moreDetailDialog";
    }
    @RequestMapping(value = "/morePhoneDetailDialogInit", method = RequestMethod.GET)
    public Object morePhoneDetailDialogInit(ModelMap model) {
        return "/account/morePhonesDetailDialog";
    }
    @RequestMapping(value = "/leftTreeDeleteDialogInit", method = RequestMethod.GET)
    public Object leftTreeDeleteDialogInit(ModelMap model) {
    	return "/account/accountBodyDelete";
    }
    @RequestMapping(value = "/moreCardTransDetailDialogInit", method = RequestMethod.GET)
    public Object moreCardTransDetailDialogInit(ModelMap model) {
        return "/account/moreCardTransDetailDialog";
    }
    @RequestMapping(value = "/moreCardInTransDetailDialogInit", method = RequestMethod.GET)
    public Object moreCardInTransDetailDialogInit(ModelMap model) {
    	return "/account/moreCardInTransDetailDialog";
    }
    @RequestMapping(value = "/moreCardOutTransDetailDialogInit", method = RequestMethod.GET)
    public Object moreCardOutTransDetailDialogInit(ModelMap model) {
    	return "/account/moreCardOutTransDetailDialog";
    }
    @RequestMapping(value = "/inaccountStatisticsD3Init", method = RequestMethod.GET)
	public Object inaccountStatisticsD3Init(ModelMap model) {
		return "/stream/inAccountStatisticsD3";
	}
    @RequestMapping(value = "/inaccountStatisticsDialogInit", method = RequestMethod.GET)
    public Object inaccountStatisticsDialogInit(ModelMap model) {
        return "/stream/inAccountStatisticsDialog";
    }
    @RequestMapping(value = "/outaccountStatisticsD3Init", method = RequestMethod.GET)
	public Object outaccountStatisticsD3Init(ModelMap model) {
		return "/stream/outAccountStatisticsD3";
	}
    @RequestMapping(value = "/exceptionAnalysisDialogInit", method = RequestMethod.GET)
    public Object exceptionAnalysisDialogDialogInit(ModelMap model) {
        return "/methodsanalysis/exceptionAnalysisDialog";
    }
    @RequestMapping(value = "/moreQQDetailDialogInit", method = RequestMethod.GET)
    public Object moreQQDetailDialogInit(ModelMap model) {
    	return "/account/moreQQDetailDialog";
    }
    @RequestMapping(value = "/moreWeChatDetailDialogInit", method = RequestMethod.GET)
    public Object moreWeChatDetailDialogInit(ModelMap model) {
    	return "/account/moreWeChatDetailDialog";
    }
    @RequestMapping(value = "/moreAliPayDetailDialogInit", method = RequestMethod.GET)
    public Object moreAliPayDetailDialogInit(ModelMap model) {
    	return "/account/moreAliPayDetailDialog";
    }
    @RequestMapping(value = "/showPersonTagPage", method = RequestMethod.GET)
    public Object showPersonTagPage(ModelMap model) {
    	return "/account/tagPersonInformation";
    }
    
    /**
     * 人员档案详情请求
     * @param accountBody
     * @return
     */
	@ResponseBody
    @RequestMapping(method= RequestMethod.POST,value = "/getPersonInformation")
    public Result getPersonInformation(@RequestBody Map<String, String> paramsMap){
     	Map<String, Object> map = new HashMap<String,Object>();
    	String showNumber = paramsMap.get("showNumber");
    	String caseId = paramsMap.get("caseId")==null ? "" : paramsMap.get("caseId");
    	//如果选择交易主体
    	if(paramsMap.get("level").toString().equals("0")) {
    		List<DealFlow> ds = null;
    		String accountBody = paramsMap.get("accountBody");
        	if(StringUtils.isNotEmpty(accountBody) && !accountBody.contains("未知")) {
        		accountBody = com.mairuide._frame.utils.StringUtils.delHTMLTag(accountBody.replace("\"", ""));
        		ds = dealFlowService.findByAccountBodyAndCasemanageIdGroupByAccountBody(accountBody, caseId);
        	}
            if(ds != null && ds.size() > 0) {
            	//查询人员基础信息
            	PersonInformation pi = null;
            	if(com.mairuide._frame.utils.StringUtils.isEmpty(ds.get(0).getIdNumber())) {
            		pi = personInformationService.findByPersonName(ds.get(0).getAccountBody());
            	}else {
            		pi = personInformationService.findPersonInformationByIdNumber(ds.get(0).getIdNumber());
            	}
            	if(null != pi) {
            		pi.setStrDate(com.mairuide._frame.utils.StringUtils.formatDate(pi.getBirthDate(), "yyyy-MM-dd"));
            		//查询卡号、余额、交易次数等信息
            		List<String> cards = ds.stream().map(e -> e.getAccountBodyCard()).collect(Collectors.toList());
            		List<PersonCards> pcs = dealFlowService.findPersonCards(caseId, showNumber, pi.getIdNumber(),cards);
            		List<Map<String,Object>> phones = dealFlowService.findPersonInformationPhone(pi.getIdNumber(), showNumber);
            		List<String> serverNumbers = phones.stream().map(e -> e.get("serviceNumber").toString()).collect(Collectors.toList());
            		List<Map<String ,Object>> alipayMap = dealFlowService.findPersonInformationAlipay(serverNumbers, "6");
            		List<Map<String ,Object>> weChatMap = dealFlowService.findPersonInformationTencentWechat(serverNumbers, "6");
            		List<Map<String ,Object>> qqMap = dealFlowService.findPersonInformationTencentQQ(serverNumbers, "6");
            		map.put("pcs", pcs);
            		map.put("phones", phones);
            		map.put("alipayMap", alipayMap);
            		map.put("weChatMap", weChatMap);
            		map.put("qqMap", qqMap);
            	}
            	map.put("pi", pi);
            	return new Result(true,StatusCode.OK,"查询成功",map);
            }else {
            	map.put("pi", null);
            	String[] accountBodyCards = paramsMap.get("cardNumbers").split(",");
            	List<String> accCards = new ArrayList<String>();
            	if(null != accountBodyCards && accountBodyCards.length > 0) {
            		for(String card : accountBodyCards) {
            			accCards.add(card);
            		}
            	}
            	List<PersonCards> pcs = dealFlowService.findPersonCards(caseId, showNumber, null,accCards);
            	map.put("pcs", pcs);
        		map.put("phones", null);
        		map.put("alipayMap", null);
        		map.put("weChatMap", null);
        		map.put("qqMap", null);
        		return new Result(true,StatusCode.OK,"查询成功",map);
            }
    	}else {//选择卡号
    		String accountBodyCard = paramsMap.get("accountBodyCard");
    		List<DealFlow> ds = dealFlowService.findByAccountBodyCardAndCasemanageIdGroupByAccountBody(accountBodyCard, caseId);
    		if(null !=  ds && ds.size() > 0) {
    			DealFlow d = ds.get(0);
    			List<Map<String,Object>> cardsTransMap = dealFlowService.findPersonInformationCardsTrans(accountBodyCard, d.getIdNumber(), "6", caseId);
    			List<Map<String,Object>> cardsInTransMap = dealFlowService.findPersonInformationCardsInTrans(accountBodyCard, d.getIdNumber(), "6", caseId, "0");
    			List<Map<String,Object>> cardsOutTransMap = dealFlowService.findPersonInformationCardsInTrans(accountBodyCard, d.getIdNumber(), "6", caseId, "1");
    			map.put("ds", ds.get(0));
    			map.put("cardsTransMap", cardsTransMap);
    			map.put("cardsInTransMap", cardsInTransMap);
    			map.put("cardsOutTransMap", cardsOutTransMap);
    		}else {
    			map.put("ds", null);
    			map.put("cardsTransMap", null);
    			map.put("cardsInTransMap", null);
    			map.put("cardsOutTransMap", null);
    		}
    		return new Result(true,StatusCode.OK,"查询成功",map);
    	}
    	
    }

    /**
     * 分页查询档案详情主题卡号交易统计
     * @param paramsMap
     * @param pagesupport
     * @param size
     * @param sortName
     * @param sortOrder
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreAccountBodyCardsTramnsDetails",method=RequestMethod.POST)
    public Object moreAccountBodyCardsTramnsDetails(String accountBody,String cardNumbers, Integer page,Integer rows,String sort,String order,String caseId) {
		Map<String, Object> result = new HashMap<String,Object>();
		if(!accountBody.contains("未知")) {
			List<DealFlow> ds = dealFlowService.findByAccountBodyAndCasemanageIdGroupByAccountBody(accountBody, caseId);
			if(null !=  ds && ds.size() > 0) {
				DealFlow d = ds.get(0);
				List<String> cards = ds.stream().map(e -> e.getAccountBodyCard()).collect(Collectors.toList());
				//查询卡号、余额、交易次数等信息
				PageResult pcs = dealFlowService.getPersionInformationCardsTransByPage(d.getIdNumber(), caseId, page, rows,sort, order,cards);
				result.put("total", pcs.getTotal());
				result.put("rows", pcs.getRows());
			}
		}else {
			String[] cards = cardNumbers.split(",");
			List<String> cardss = new ArrayList<String>();
			for(String card : cards) {
				cardss.add(card);
			}
			//查询卡号、余额、交易次数等信息
			PageResult pcs = dealFlowService.getPersionInformationCardsTransByPage(null, caseId, page, rows,sort, order,cardss);
			result.put("total", pcs.getTotal());
			result.put("rows", pcs.getRows());
		}
		return result;
    }
	/**
	 * 分页查询档案详情手机号码统计
	 * @param idNumber
	 * @param pagesupport
	 * @param sortName
	 * @param sortOrder
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/morePhoneDetails",method=RequestMethod.POST)
    public Object morePhoneDetails(String paramsIdNumber, Integer page,Integer rows, String sort, String order) {
		Map<String, Object> result = new HashMap<String,Object>();
		if(com.mairuide._frame.utils.StringUtils.isEmpty(paramsIdNumber)) {
			return result;
		}
		PageResult pr = dealFlowService.getPersionInformationPhonesByPage(paramsIdNumber, page, rows, sort, order);
		result.put("total", pr.getTotal());
		result.put("rows", pr.getRows());
		return result;
    }
    /**
     * 分页查询档案详情卡号交易详情信息
     * @param paramsMap
     * @param pagesupport
     * @param size
     * @param sortName
     * @param sortOrder
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreCardTramnsDetails",method=RequestMethod.POST)
    public Object getPersionInformationCardTransByPage(String accountBodyCard, Integer page,Integer rows, String sort,String order,String caseId) {
    	List<DealFlow> ds = dealFlowService.findByAccountBodyCardAndCasemanageIdGroupByAccountBody(accountBodyCard, caseId);
    	Map<String, Object> result = new HashMap<String,Object>();
    	if(null !=  ds && ds.size() > 0) {
    		DealFlow d = ds.get(0);
    		if(com.mairuide._frame.utils.StringUtils.isEmpty(d.getIdNumber())) {
    			return result;
    		}
    		PageResult pr =  dealFlowService.getPersionInformationCardTransByPage(accountBodyCard, d.getIdNumber(), caseId, page, rows, sort, order);
    		result.put("total", pr.getTotal());
    		result.put("rows", pr.getRows());
    	}
		return result;
    }
	
	/**
     * 分页查询档案详情卡号流入交易详情信息
     * @param paramsMap
     * @param pagesupport
     * @param size
     * @param sortName
     * @param sortOrder
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreCardInTramnsDetails",method=RequestMethod.POST)
    public Object moreCardInTramnsDetails(String accountBodyCard, Integer page,Integer rows, String sort,String order,String caseId) {
    	List<DealFlow> ds = dealFlowService.findByAccountBodyCardAndCasemanageIdGroupByAccountBody(accountBodyCard, caseId);
    	Map<String, Object> result = new HashMap<String,Object>();
    	if(null !=  ds && ds.size() > 0) {
    		DealFlow d = ds.get(0);
    		if(com.mairuide._frame.utils.StringUtils.isEmpty(d.getIdNumber())) {
    			return result;
    		}
    		PageResult pr =  dealFlowService.getPersionInformationCardInTransByPage(accountBodyCard,d.getIdNumber(), "0",caseId, page, rows, sort, order);
    		result.put("total", pr.getTotal());
    		result.put("rows", pr.getRows());
    	}
		return result;
    }
	
	/**
     * 分页查询档案详情卡号流出交易详情信息
     * @param paramsMap
     * @param pagesupport
     * @param size
     * @param sortName
     * @param sortOrder
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreCardOutTramnsDetails",method=RequestMethod.POST)
    public Object moreCardOutTramnsDetails(String accountBodyCard, Integer page,Integer rows, String sort,String order,String caseId) {
    	List<DealFlow> ds = dealFlowService.findByAccountBodyCardAndCasemanageIdGroupByAccountBody(accountBodyCard, caseId);
    	Map<String, Object> result = new HashMap<String,Object>();
    	if(null !=  ds && ds.size() > 0) {
    		DealFlow d = ds.get(0);
    		if(com.mairuide._frame.utils.StringUtils.isEmpty(d.getIdNumber())) {
    			return result;
    		}
    		PageResult pr =  dealFlowService.getPersionInformationCardInTransByPage(accountBodyCard,d.getIdNumber(), "1",caseId, page, rows, sort, order);
    		result.put("total", pr.getTotal());
    		result.put("rows", pr.getRows());
    	}
		return result;
    }
    
    /**
     * 编辑人员详情
     * @param paramsMap
     * @return
     */
    @ResponseBody
    @RequestMapping(method= RequestMethod.POST,value = "/editPersonInformation")
    public Object editPersonInformation(@RequestBody PersonInformationParams pip){
    	String caseId=pip.getCasemanagerId();
    	//如果没有没有修改姓名则不更新该主题下所属卡号等信息
    	if(!pip.getPersonName().equals(pip.getOldPersonName())) {
    		//如果该主题下有卡号则更新卡号到新的交易主体下，如果没有则只更新主题名称
    		if(com.mairuide._frame.utils.StringUtils.isNotEmpty(pip.getCardNumbers())) {
    			List<String> accountBodyCards = Arrays.asList(pip.getCardNumbers().split(","));
    			dealFlowService.findByAccountBodyCardAndCasemanageId(accountBodyCards, caseId,pip.getPersonName(),pip.getIdNumber(),pip.getBodyType());
    		}else {
    			dealFlowService.findByAccountBodyAndCasemanageId(pip.getOldPersonName(), caseId,pip.getPersonName(),pip.getIdNumber(),pip.getBodyType());
    		}
    	}else {
    		dealFlowService.findByAccountBodyAndCasemanageId(pip.getOldPersonName(), caseId,pip.getPersonName(),pip.getIdNumber(),pip.getBodyType());
    	}
    	//查询人员表是否存在修改的人，如果存在删除后更新，如果不存在则插入
    	PersonInformation person = personInformationService.findByPersonName(pip.getPersonName());
    	//判断修改的手机号码不为空并且存在话单则更新话单的身份证信息和主叫号码姓名
    	if(StringUtils.isNotEmpty(pip.getPhoneNumber())) {
    		List<PhoneRecord> pr = phoneRecordingService.findByServiceNumberAndCasemanageIdAndIsDelete(pip.getPhoneNumber(), pip.getCasemanagerId(), 0);
    		if(pr != null) {
    			for(PhoneRecord p : pr) {
    				p.setIdNumber(pip.getIdNumber());
    				p.setServiceUserInformation(pip.getPersonName());
    				phoneRecordingService.save(p);
    			}
    		}
    	}
		if(person == null) {
			PersonInformation p = new PersonInformation();
			p.setPersonName(pip.getPersonName());
			p.setIdNumber(pip.getIdNumber());
			p.setBodyType(pip.getBodyType());
			p.setCasemanagerId(caseId);
			p.setBirthDate(DateUtils.stringToTimestamp(pip.getBirthDate()));
			p.setBirthPlace(pip.getBirthPlace());
			p.setGender(pip.getGender());
			p.setPhoneNumber(pip.getPhoneNumber());
			p.setMaritalStatus(pip.getMaritalStatus());
			p.setNational(pip.getNational());
			p.setNationality(pip.getNationality());
			p.setRemark(pip.getRemark());
			p.setDataSource("左侧菜单手动录入");
			personInformationService.save(p);
		}else {
			if(com.mairuide._frame.utils.StringUtils.isNotEmpty(pip.getOldPersonName())) {
				personInformationService.deleteByPersonName(pip.getOldPersonName());
			}
			person.setPersonName(pip.getPersonName());
			if(com.mairuide._frame.utils.StringUtils.isNotEmpty(pip.getIdNumber())) {
				person.setIdNumber(pip.getIdNumber());
			}
			if(com.mairuide._frame.utils.StringUtils.isNotEmpty(pip.getBodyType())) {
				person.setBodyType(pip.getBodyType());
			}
			person.setCasemanagerId(caseId);
			person.setPhoneNumber(pip.getPhoneNumber());
			person.setBirthPlace(pip.getBirthPlace());
			person.setGender(pip.getGender());
			person.setMaritalStatus(pip.getMaritalStatus());
			person.setNational(pip.getNational());
			person.setNationality(pip.getNationality());
			person.setRemark(pip.getRemark());
			person.setDataSource("左侧菜单手动修改");
			personInformationService.save(person);
		}
		return SUCCESS();
    }
    
    /**
     * 分页查询qq交易信息
     * @param idNumber
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreQQTramnsDetails",method=RequestMethod.POST)
    public Object moreQQTramnsDetails(String paramsIdNumber, Integer page,Integer rows,String sort,String order) {
		Map<String, Object> result = new HashMap<String,Object>();
		List<Map<String,Object>> phones = dealFlowService.findPersonInformationPhone(paramsIdNumber, "");
		List<String> serverNumbers = phones.stream().map(e -> e.get("serviceNumber").toString()).collect(Collectors.toList());
		PageResult pr = dealFlowService.findPersonInformationTencentQQEasyUi(serverNumbers, page, rows, sort, order);
		result.put("total", pr.getTotal());
		result.put("rows", pr.getRows());
		return result;
    }
	/**
     * 分页查询微信交易信息
     * @param idNumber
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value="/moreWeChatTramnsDetails",method=RequestMethod.POST)
    public Object moreWeChatTramnsDetails(String paramsIdNumber, Integer page,Integer rows,String sort,String order) {
		Map<String, Object> result = new HashMap<String,Object>();
		List<Map<String,Object>> phones = dealFlowService.findPersonInformationPhone(paramsIdNumber, "");
		List<String> serverNumbers = phones.stream().map(e -> e.get("serviceNumber").toString()).collect(Collectors.toList());
		PageResult pr = dealFlowService.findPersonInformationTencentWechatEasyUi(serverNumbers, page, rows, sort, order);
		result.put("total", pr.getTotal());
		result.put("rows", pr.getRows());
		return result;
    }
	/**
	 * 分页查询支付宝交易信息
	 * @param paramsIdNumber
	 * @param page
	 * @param rows
	 * @param sort
	 * @param order
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@ResponseBody
	@RequestMapping(value="/moreAliPayTramnsDetails",method=RequestMethod.POST)
	public Object moreAliPayTramnsDetails(String paramsIdNumber, Integer page,Integer rows,String sort,String order) {
		Map<String, Object> result = new HashMap<String,Object>();
		List<Map<String,Object>> phones = dealFlowService.findPersonInformationPhone(paramsIdNumber, "");
		List<String> serverNumbers = phones.stream().map(e -> e.get("serviceNumber").toString()).collect(Collectors.toList());
		PageResult pr = dealFlowService.findPersonInformationTencentAliPayEasyUi(serverNumbers, page, rows, sort, order);
		result.put("total", pr.getTotal());
		result.put("rows", pr.getRows());
		return result;
	}
	
    /**
	 * 删除交易主体名称
	 * @param model
	 * @param accountBody
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/deleteAccountBody", method=RequestMethod.POST)
	public Object deleteForm(ModelMap model,@RequestBody Map<String,String> params) throws Exception {
		String caseId=params.get("caseId")==null?"":params.get("caseId");
		if(StringUtils.isNotEmpty(params.get("cardNumbers"))) {
			List<String> accountBodyCards = Arrays.asList(params.get("cardNumbers").split(","));
			dealFlowService.deleteByAccountBodyCardAndCasemanageId(accountBodyCards, caseId);
		}else {
			dealFlowService.deleteByAccountBodyAndCasemanageId(params.get("nodeText"), caseId);
		}
		personInformationService.deleteByPersonName(params.get("nodeText"));
		return SUCCESS();
	}
	
	/**
	 * 编辑回显
	 * @param qm
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getPersonTag",method = RequestMethod.POST)
    public Object editQuestion(@RequestBody Map<String,Object> qm){
		Map<String,Object> result = new HashMap<String,Object>();
		if(null != qm.get("personId") && StringUtils.isNotEmpty(qm.get("personId").toString())) {
			List<PersonTag> pts = personTagService.findByPersonId(Integer.parseInt(qm.get("personId").toString()));
			List<String> ps = pts.stream().map(e -> e.getTagName()).collect(Collectors.toList());
			result.put("ps", ps);
		}
		return result;
    }
	
	/**
	 * 新增修改
	 * @param model
	 * @param id
	 * @param userType
	 * @return
	 */
	@ResponseBody
	@PostMapping("/addAndEditQuestion")
	public Object addAndEditPersonTag(ModelMap model, @RequestBody Map<String,Object> qm) {
		if(null == qm) {
			return ERROR("保存失败");
		}
		Object p = qm.get("personId");
		//先将原有标签删除然后新增
		personTagService.deleteByPersonId(Integer.parseInt(qm.get("personId").toString()));
		if(com.mairuide._frame.utils.StringUtils.isNotEmpty(qm.get("sbparticiples").toString())) {
			String[] sbpar = qm.get("sbparticiples").toString().split(",");
			for(String sbp : sbpar) {
				PersonTag mp = new PersonTag();
				mp.setPersonId(Integer.parseInt(qm.get("personId").toString()));
				mp.setTagName(sbp);
				personTagService.save(mp);
			}
		}
		return SUCCESS();
	}
	
    
    @RequestMapping(method= RequestMethod.POST,value = "/inaccountstatistics_d3")
    @ResponseBody
    public Result getInStreamAccountCount(@RequestBody DealFlowDto dealFlowdto){
        return new Result(true, StatusCode.OK,"查询成功",transactionStreamD3Service.getInStreamAccountD3(dealFlowdto));
    }
    @RequestMapping(method= RequestMethod.POST,value = "/outaccountstatistics_d3")
    @ResponseBody
    public Result getOutStreamAccountCount(@RequestBody DealFlowDto dealFlowdto){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        dealFlowdto.setCasemanageId(caseId);
        return new Result(true, StatusCode.OK,"查询成功",transactionStreamD3Service.getOutStreamAccountD3(dealFlowdto));
    }
    @RequestMapping(method= RequestMethod.POST,value = "/inbodystatistics_d3")
    @ResponseBody
    public Result geInStreamBodyCount(@RequestBody DealFlowDto dealFlowdto){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        dealFlowdto.setCasemanageId(caseId);
        return new Result(true, StatusCode.OK,"查询成功",transactionStreamD3Service.getInStreamBodyD3(dealFlowdto));
    }
    @RequestMapping(method= RequestMethod.POST,value = "/outbodystatistics_d3")
    @ResponseBody
    public Result geOutStreamBodyCount(@RequestBody DealFlowDto dealFlowdto){
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        dealFlowdto.setCasemanageId(caseId);
        return new Result(true, StatusCode.OK,"查询成功",transactionStreamD3Service.getOutStreamBodyD3(dealFlowdto));
    }
    @RequestMapping(method= RequestMethod.POST,value = "/getInD3Tree")
    @ResponseBody
    public Object getInD3Tree(@RequestBody DealFlowDto dealFlowdto){
        return transactionStreamD3Service.getInD3Tree(dealFlowdto);
    }
    @RequestMapping(method= RequestMethod.POST,value = "/getOutD3Tree")
    @ResponseBody
    public Object getOutD3Tree(@RequestBody DealFlowDto dealFlowdto){
    	return transactionStreamD3Service.getOutD3Tree(dealFlowdto);
    }
}
